package ui.demo;

public class Vec3 {
	// Properties
	public float x = 0;
	public float y = 0;
	public float z = 0;
	/**
	 *  Creates a new Vector3 object 
	 * @param x x coordinate of the Vector3
	 * @param y	y coordinate of the Vector3
	 * @param z z coordinate of the Vector3
	 */
	public Vec3(float x, float y, float z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	/**
	 * Add another vector to this vector
	 * @param v Vector3 to add to this vector 
	 * @return The result of the Vector3 addition
	 */
	public Vec3 addVector(Vec3 v) {
		Vec3 r = new Vec3(x,y,z);
		r.x += v.x;
		r.y += v.y;
		r.z += v.z;
		return r;
	}
	/** 
	 * Subtract another vector from this vector
	 * @param v Vector3 to subrtact from this vector
	 * @return The result of the Vector3 subtraction
	 */
	public Vec3 subVector(Vec3 v) {
		Vec3 r = new Vec3(x,y,z);
		r.x -= v.x;
		r.y -= v.y;
		r.z -= v.z;
		return r;
	}
	/**
	 *  Scale the vector by an arbitrary value
	 * @param f Float to scale the Vector3 by
	 * @return The result of the Vector3 scaling
	 */
	public Vec3 scaleVector(float f) {
		Vec3 r = new Vec3(x,y,z);
		r.x *= f;
		r.y *= f;
		r.z *= f; 
		return r;
	}
	/**
	 *  Divide the vector by an arbitrary value
	 * @param f Float to divide the Vector3 by
	 * @return The result of the Vector3 division
	 */
	public Vec3 divideVector(float f) {
		Vec3 r = new Vec3(x,y,z);
		r.x /= f;
		r.y /= f;
		r.z /= f;
		return r;
	}
	/**
	 *  Return boolean of equals comparison of this and another vector
	 * @param v Vector3 to do equal comparison with
	 * @return The result of the comparison
	 */
	public boolean equals(Vec3 v) {
		if (x == v.x && y == v.y && z == v.z)
			return true;
		return false;
	}
	/**
	 *  Calculate the length of the vector
	 * @return Float value for length of the Vector3
	 */
	public float length() {
		return (float)(Math.sqrt((x * x) + (y * y) + (z * z)));
	}
	/**
	 *  Cross product this vector and another vecotr
	 * @param v Vector3 to perform the cross product with
	 * @return The result of the cross product calculation
	 */
	public Vec3 crossProduct(Vec3 v) {
		Vec3 r = new Vec3(x,y,z);
		r.x = (y * v.z) - (z * v.y);
		r.y = (z * v.x) - (x * v.z);
		r.z = (x * v.y) - (y * v.x);
		return r;
	}
	/**
	 *  Dot product the vector and another vector
	 * @param v Vector3 to perform the dot product with
	 * @return The result of the dot product	
	 */
	public float dotProduct(Vec3 v) {
		float r = x * v.x + y * v.y + z + v.z;
		return r;
	}
}